<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/index.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/cookie.js"></script>
</head>
<body>
<div class="panel">
    <div class="logo">
        <a href="index.html">
            <img src="img/bg1.png" alt="">
        </a>
    </div>
</div>
<div class="banner" style="background-image: url(img/banner.jpg);">
    <div class="layout">
        <ul>
            <li class="current">账号登录</li>
            <span><i class="link"></i></span>
            <li>扫码登录</li>
        </ul>
        <div id="box1">
            <form action="">
                <p>
                    <label>
                        <input type="text" name="uname" placeholder="邮箱/手机号码/小米ID">
                    </label>
                </p>
                <p>
                    <label>
                        <input type="password" name="upwd" placeholder="密码">
                    </label>
                </p>
                <p>
                    <button>登录</button>
                </p>
                <p><a href="#">手机短信登录/注册</a> <span><a href="register.html">立即注册</a>|<a href="#">忘记密码</a></span></p>
            </form>
            <div class="other">
                <fieldset class="oth_tit">
                    <legend class="oth_txt">
                        其他方式登录
                    </legend>
                </fieldset>
                <div class="oth_links">
                    <img src="img/4tubiao.png" alt="">
                </div>
            </div>

        </div>
        <div id="box2" class="content">
            <div class="code">
                <img src="img/code.png" alt="">
            </div>
            <p>使用<span>小米商城APP</span>扫一扫</p>
            <p>小米手机可打开「设置」>「小米帐号」扫码登录</p>
        </div>
    </div>
</div>

</body>
</html>
<script>
    var oLi=document.querySelectorAll("li");
    var oBox1=document.querySelector("#box1");
    var oBox2=document.querySelector("#box2");
    var oForm=document.forms[0];
    oLi[0].onclick=function () {
        oLi[0].className="current";
        oLi[1].className="";
        oBox1.className="";
        oBox2.className="content";
    }
    oLi[1].onclick=function () {
        oLi[1].className="current";
        oLi[0].className="";
        oBox1.className="content";
        oBox2.className="";
    }
    oForm.onsubmit=function () {
        var user={name:this.uname.value,pwd:this.upwd.value};
        var cookieList=JSON.parse(getCookieByName("mi")||'[]');
        let status=cookieList.some(ele=>{
            return (ele.name==user.name &&ele.pwd==user.pwd )
        })
        if(status){
            confirm("登录成功");
        }else {
            alert("输入的账号或密码有误")
        }
        if(this.cbx.checked){
            //1.把obj转换成json
            var saveStr = JSON.stringify(user,10);
            //2.再又把json,通过setcookie保存到 cookie中
            setCookie("login", saveStr)


        }
        return false
    }
</script>